//
//  ScanLoginViewController.m
//  SouthChina
//
//  Created by kc on 15/11/17.
//  Copyright © 2015年 科创. All rights reserved.
//  扫描二维码登陆界面

#import "ScanLoginViewController.h"

@interface ScanLoginViewController ()

@end

@implementation ScanLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [super addTitleBarWithBackBtn:@"二维码登录" needReturn:YES];
    //显示图片
    //UIImageView *imgBK = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH*0.2, TITLE_BAR_HEGIHT+YNEW+30, SCREEN_WIDTH*0.6, SCREEN_WIDTH*0.6)];
    UIImageView *imgBK = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH*0.2, TITLE_BAR_HEGIHT+YNEW+SCREEN_HEIGHT*0.08, SCREEN_WIDTH*0.6, SCREEN_WIDTH*0.6)];
    imgBK.image = [UIImage imageNamed:@"scan_login.png"];
    [self.view addSubview:imgBK];
    
    //标题
    UILabel *lbName = [[UILabel alloc]initWithFrame:CGRectMake(imgBK.frame.origin.x, imgBK.frame.origin.y+imgBK.frame.size.height+20, imgBK.frame.size.width, 20)];
    lbName.text = @"移动校园门户登录确认";
    lbName.textAlignment = NSTextAlignmentCenter;
    [lbName setFont:[UIFont systemFontOfSize:18]];
    [self.view addSubview:lbName];
    
    //登陆按钮
    //UIButton *btLogin = [[UIButton alloc]initWithFrame:CGRectMake(10, lbName.frame.origin.y+lbName.frame.size.height+40, SCREEN_WIDTH-20, 40)];
    UIButton *btLogin = [[UIButton alloc]initWithFrame:CGRectMake(10, 0.8*SCREEN_HEIGHT, SCREEN_WIDTH-20, 40)];
    [btLogin setTitle:@"登录" forState:UIControlStateNormal];
    btLogin.backgroundColor = BASIC_BLUE_COLOR;
    [self.view addSubview:btLogin];
    [btLogin addTarget:self action:@selector(ScanLoginBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    //取消登陆
    UIButton *btCancleLogin = [[UIButton alloc]initWithFrame:CGRectMake(10, btLogin.frame.origin.y+btLogin.frame.size.height+15, SCREEN_WIDTH-20, 40)];
    [btCancleLogin setTitle:@"取消登录" forState:UIControlStateNormal];
    [btCancleLogin setTitleColor:[UIColor grayColor] forState:UIControlStateNormal]
    ;
    [self.view addSubview:btCancleLogin];
    [btCancleLogin addTarget:self action:@selector(CancleScanLoginBtn:) forControlEvents:UIControlEventTouchUpInside];
}


//扫描登陆，调用接口 portalLogin，传入参数 tokenId，成功后返回
-(void)ScanLoginBtn:(UIButton*)btn
{
    if([_sDetail isEqualToString:@""])
        return;
    
    NSDictionary *map = @{@"tokenId":_sDetail};
    [DE serverCall:@"portalLogin" params:map callback:^(BOOL success, int code, NSString *desc, NSDictionary *data,NSDictionary*param) {
        NSString *sReturnInfo = @"";
        if(success)
        {
            sReturnInfo = @"登录成功";
        }
        else{
            sReturnInfo = @"登录失败";
        }
        //拼接类型
        sReturnInfo = [sReturnInfo stringByAppendingString:_srootVC];
        NSLog(@"消息内容为：%@",sReturnInfo);
        [[NSNotificationCenter defaultCenter] postNotificationName:SCAN_LOGIN_MSG object:sReturnInfo];
        
        [kAppDelegate.iCSDrawerController.navigationController popToRootViewControllerAnimated:YES];
    }
     ];
}

//取消登陆，回到上一层界面
-(void)CancleScanLoginBtn:(UIButton*)btn
{
    [kAppDelegate.iCSDrawerController.navigationController popToRootViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
